package src;
/**
 * Die Klasse <code>UserAccount</code> implementiert ein Benutzerkonto.
 * 
 * @author anon
 * @version 26.11
 * 
 */

// ############################## Datenfelder ##############################

public class UserAccount {
	private String email;
	private String name;
	private String pi;
	private double accumulatedOverdraftFee;

// ############################## Konstruktoren ##############################

	public UserAccount(String name, String personIdentifier, String email) {
		if (name == null || email == null || personIdentifier == null)
			throw new NullPointerException();
		this.name = name;
		this.pi = personIdentifier;
		this.email = email;
		accumulatedOverdraftFee = 0.0;
	}

	public UserAccount(UserAccount ua) {
		this.email = ua.getEMail();
		this.name = ua.getName();
		this.pi = ua.getIdentifier();
		this.accumulatedOverdraftFee = ua.getAccumulatedOverdraftFee();
	}

// ############################## Methoden ##############################

	public String getEMail() {
		return this.email;
	}

	public void setEMail(String email) {
		if (email == null)
			throw new NullPointerException();
		this.email = email;
	}

	public String getName() {
		return this.name;
	}

	public void setName(String name) {
		if (name == null)
			throw new NullPointerException();
		this.name = name;
	}

	public String getIdentifier() {
		return this.pi;
	}

	public double getAccumulatedOverdraftFee() {
		return this.accumulatedOverdraftFee;
	}

	public void addToAccumulatedOverdraftFee(double amount) {
		if (amount < 0)
			throw new IllegalArgumentException();
		accumulatedOverdraftFee = accumulatedOverdraftFee + amount;
	}

	public void subtractFromAccumulatedOverdraftFee(double amount) {
		if (amount < 0)
			throw new IllegalArgumentException();
		accumulatedOverdraftFee = accumulatedOverdraftFee - amount;
	}

	@Override
	public String toString() {
		return "UserAccount[name=" + name + ",identifier=" + pi + ",email="
				+ email + ",overdraftFee=" + accumulatedOverdraftFee + "]";
	}

	@Override
	public boolean equals(Object obj) {
		if (obj instanceof UserAccount) {
			UserAccount ua = (UserAccount) obj;
			if (email.equals(ua.getEMail()))
				if (name.equals(ua.getName()))
					if (pi.equals(ua.getIdentifier()))
						if (accumulatedOverdraftFee == ua
								.getAccumulatedOverdraftFee())
							return true;
		}
		return false;
	}

}
